package com.brainhealth.web.controller.common;


import com.brainhealth.common.core.domain.AjaxResult;
import com.brainhealth.customer.service.IWebsocketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/websocket")
public class WebsocketController
{
    @Autowired
    IWebsocketService websocketService;

    /**
     * 推送给所有用户
     *
     * @param map
     */
    @PostMapping("pushAll")
    public AjaxResult pushToAll(@RequestBody Map<String, String> map)
    {
        String msg = map.get("msg");
        websocketService.pushMsgToAll(msg);
        return AjaxResult.success("推送消息成功！");
    }

    /**
     * 推送给指定用户
     *
     */
    @PostMapping("pushOne")
    public AjaxResult pushMsgToOne(@RequestBody Map<String, Object> map)
    {
        String phone = map.get("phone").toString();
        String msg = map.get("msg").toString();
        websocketService.pushMsgToOne(phone, msg);
        return AjaxResult.success("推送消息成功！");
    }

    /**
     * 获取当前在线的用户
     */
    @PostMapping("/getOnlineCustomer")
    public AjaxResult getOnlineCustomer()
    {
        return AjaxResult.success(websocketService.getOnlineCustomerList());
    }
}
